<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>新的提交</title>
    <script src="../../js/jquery.js"></script>
    <script src="../../layui/layui.js"></script>
    <link rel="stylesheet" href="../../layui/css/layui.css">
    <script src="../../js/myAjax.js"></script>
    <script src="../../js/utlis/edit.js"></script>
</head>
<body>
<div style="margin-left: 80px; margin-top: 50px">
    <div type="hidden" id="wordId"></div>
    <div class="layui-form-item">
        <label class="layui-form-label">单词</label>
        <div class="layui-input-inline">
            <input type="text" name="word"  required lay-verify="required" id="word" autocomplete="off"
                   class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">翻译</label>
        <div class="layui-input-inline">
            <input type="text" name="translate"  required lay-verify="required" id="translate" autocomplete="off"
                   class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">提交时间</label>
        <div class="layui-input-inline">
            <input type="text" name="subTime"  required lay-verify="required" id="subTime" autocomplete="off"
                   class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" onclick="editAdd('/w/word/edit',getData())">确认添加</button>
            <button type="reset" onclick="resetAdd('/html/word/editSub.html')" class="layui-btn layui-btn-primary">
                点击重置
            </button>
        </div>
    </div>
</div>
<script>
    layui.use('laydate', function(){
        var laydate = layui.laydate;
        //执行一个laydate实例
        laydate.render({
            elem: '#subTime' //指定元素
            ,type: 'datetime'
            ,format: 'yyyy-MM-dd HH:mm:ss'
        });
    });
    function getData() {
        let data = {
            id:sessionStorage.getItem("wordId"),
            word: $("#word").val(),
            translate: $("#translate").val(),
            submitter: localStorage.getItem("username"),
            subTime: $("#subTime").val(),
            heat: 0
        }
        return data;
    }
    layui.use('form', function(){
        var form = layui.form;
        //监听提交
        form.on('submit(formDemo)', function(){
            // layer.msg(JSON.stringify(data.field));
            return false;
        });
    });

    let id = sessionStorage.getItem("wordId");
    findById('/w/word/findById', id);

    function findById(url, id) {
        let result = myAjax(url, 'post', {id: id});
        $("#word").val(result.data.word);
        $("#translate").val(result.data.translate);
        $("#subTime").val(result.data.subTime);
    }
</script>
</body>
</html>